<?php
	class onlinedb
	{
		// Danh sách các phương thức
		public function Add($MaSession, $TimeOut)
		{
			$now = time();
			$sql = "INSERT INTO `tbl_online`(`MaSession`, `TimeOut`)
					VALUES(" . dataservice::QuoteSmart($MaSession) . ", " . dataservice::QuoteSmart($now + $TimeOut) . ")";
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
		
		public function Update($MaSession, $TimeOut)
		{
			$now = time();
			$sql = "UPDATE `tbl_online` SET `TimeOut` = " . dataservice::QuoteSmart($now + $TimeOut) . " WHERE `MaSession` = " . dataservice::QuoteSmart($MaSession);
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
		
		public function Delete()
		{
			$now = time();
			$sql = "DELETE FROM `tbl_online` WHERE `TimeOut` < " . $now;
			
			$db = new dataservice();
			return $db->ExecuteNonQuery($sql);
		}
		
		public function GetList()
		{
			$now = time();
			$sql = "SELECT COUNT(*) AS LuotOnline FROM `tbl_online` WHERE `TimeOut` >= " . $now;
			
			$db = new dataservice();
			return $db->ExecuteQuery($sql);
		}
		
		// Các phương thức mở rộng
		public function KiemTraDB($MaSession)
		{
			$sql = "SELECT * FROM `tbl_online` WHERE `MaSession` = " . dataservice::QuoteSmart($MaSession);
			
			$db  = new dataservice();
			return $db->ExecuteQuery($sql);
		}
	}
?>